/*
 * marketsim-eclipsetrader
 *
 * Copyright (C) 2008-2011 Steve Phelps and John Cartlidge
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 */
/*
 *  (C) Victria Ltd. 2007
 */
package victria.marketsim.eclipsetrader;

import org.apache.log4j.Logger;

import victria.marketsim.eclipsetrader.event.ClockEvent;

public abstract class AbstractVisualisationClock extends
		AbstractController implements Runnable {

	static Logger logger = Logger.getLogger(AbstractVisualisationClock.class);
	
	protected ClockEvent clockEvent;

	public AbstractVisualisationClock() {
	}
	
	public AbstractVisualisationClock(ClockEvent clockEvent) {
		this.clockEvent = clockEvent;
	}
	
	public void run() {
		while (true) {
			try {
				fireClockEvent();			
				sleep();
			} catch (Exception e) {
				// Don't let clock threads die - catch and log instead
				logger.error(e);
				e.printStackTrace();
			}
		}
	}
	
	public void fireClockEvent() {
		fireEvent(clockEvent);
	}

	public ClockEvent getClockEvent() {
		return clockEvent;
	}

	public void setClockEvent(ClockEvent clockEvent) {
		this.clockEvent = clockEvent;
	}

	public abstract void sleep();
	

}
